package com.sykj.springboot.common.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

import java.util.concurrent.TimeUnit;

public class RedisUtils {


    @Autowired
    public static RedisTemplate redisTemplate;




    public static void addStringToRedis(String key,String value){
        //Redis通用的操作组件
        ValueOperations valueOperations=redisTemplate.opsForValue();
        valueOperations.set(key, value);
    }

    public static void addObjToRedis(String key,Object value){
        //Redis通用的操作组件
        ValueOperations valueOperations=redisTemplate.opsForValue();
        valueOperations.set(key, value);
    }

    public static void addToken(String key,Object value){
        //Redis通用的操作组件
        ValueOperations valueOperations=redisTemplate.opsForValue();
        valueOperations.set(key, value,600, TimeUnit.SECONDS);
    }

    public static String getStringFromRedis(String key){
        //Redis通用的操作组件
        ValueOperations valueOperations=redisTemplate.opsForValue();
        return valueOperations.get(key).toString();
    }

    public static Object getObjFromRedis(String key){
        //Redis通用的操作组件
        ValueOperations valueOperations=redisTemplate.opsForValue();
        return valueOperations.get(key);
    }

}
